<template>
  <el-row class="tac">
    <el-col :span="24">
      <el-menu
          active-text-color="#ffd04b"
          background-color="#545c64"
          class="el-menu-vertical-demo"
          default-active="this.$router.path"
          style="width: 200px;min-height:100vh"
          text-color="#fff"
          router
      >
        <el-sub-menu index="1" v-if="user.role === 1">
          <template #title>系统管理</template>
          <el-menu-item index="/user"><span>用户管理</span></el-menu-item>
        </el-sub-menu>

          <el-menu-item index="/book">书籍管理</el-menu-item>

          <el-menu-item index="/news">新闻管理</el-menu-item>

      </el-menu>
    </el-col>
  </el-row>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Aside",
  data(){
    return{
      user:{},
      path:this.$router.path //设置默认高亮
    }
  },
  created() {
    let userStr = sessionStorage.getItem("user") || "{}"
    this.user = JSON.parse(userStr)

    //请求服务端，确认当前登录用户的信息
    request.get("/user/"+this.user.id).then(res=>{
      if (res.code === '0')
      {
        this.user = res.data
      }
    })
  }
}
</script>

<style scoped>

</style>